<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>教师注册</title>

</head>
<body>
<%

String invite="abcd";
String getinvite=request.getParameter("invite");
   if(getinvite.equals(invite))
   {	
	   request.setCharacterEncoding("utf-8");
	   String DriverName = "com.mysql.jdbc.Driver";
	   String url = "jdbc:mysql://localhost:3306/student";
	   String user = "root";
	   String password = "123456";
	   Connection conn;
	   Statement stmt;
	   ResultSet rs;
	   Class.forName(DriverName);
	   conn = DriverManager.getConnection(url, user, password);
	   stmt = conn.createStatement();
	   String getid=request.getParameter("ID");
	   String getname=request.getParameter("name");
	   String getpass=request.getParameter("pass");
	   String getidentity="教师";
	   System.out.print(getid);
	   //String sql1="INSERT INTO user_t (UserID,UserName,UserPass,Identity) VALUES ('"+getid+"','"+getname+"','"+getpass+"','"+getidentity+"')";
	   String sql2="create table Task_"+getid+" (TaskID int not null primary key auto_increment,TaskTheme Text not null,TaskIssuTime Date not null,TaskDeadline Date not null,TaskGroup char(6),foreign key(TaskGroup) references Class_t(InviteID))";
	   out.print(sql2);
	   String sql3="create table TaskContent_"+getid+" (TaskID int primary key,TaskContent Text not null,CompleteStatus Text,foreign key(TaskID) references Task_UserID(TaskID))";
	   String sql4="create table FinishC_"+getid+" (TaskID int primary key,StudentID char(11) not null,SelfCompleteStatus Text,foreign key(TaskID) references Task_UserID(TaskID))";
	   	stmt.executeUpdate(sql1);
	  	stmt.executeUpdate(sql2);
	  	stmt.executeUpdate(sql3);
	  	stmt.executeUpdate(sql4);
	  
	   out.println("<script language='javascript'>alert('注册成功！');window.location.href='sign.jsp';</script>");
       
   }
   
   else
   {
   	out.println("<script language='javascript'>alert('邀请码错误，请重新输入');window.location.href='addteacher.jsp';</script>");

   }
	
%>
</body>
<html>